angular.module('cart', ['cart1'])
.config(['$stateProvider',function($stateProvider){
	$stateProvider.state('/cart',{
		url:'/cart',
		templateUrl:'html/cart/cart.html',
		css:'html/cart/cart.css',
		controller:'CartController'
	})
}]).controller('CartController', ['$scope','cart2', function($scope,cart2){
	$scope.shopCart=cart2.getProducts();
	$scope.total = function(){	//计算商品总价
		var total = 0;
		for (var i = 0; i <$scope.shopCart.length; i++) {
			total += ($scope.shopCart[i]['price'] * $scope.shopCart[i]['count']);
		}
		return total;
	}
	$scope.cut=function(arr){/*删除商品*/
		cart2.removeProduct(arr['name'])
	}
	$scope.add=function(arr){/*添加商品*/
		cart2.addProduct(arr['name'],arr['price'],arr['img'])
	}
}])